/**
 * 
 */
package com.williamoneil.charts.client.data;


/**
 * @author gudipati
 *
 */
public class BenchmarkAxis {

	private double minPriceScale = 0;
	private double maxPriceScale = 0;

	private double minTickPrice = 0;
	private double maxTickPrice = 0;
	
	// this is only updated when the benchmark is moved
	
	public BenchmarkAxis(final double minPrice, final double maxPrice) {
		this.minTickPrice = minPrice;
		this.maxTickPrice = maxPrice;
		
		minPriceScale = minTickPrice * 0.9; // 10% lower than lowest value
		maxPriceScale = maxTickPrice * 1.1; // 10% higher than higest value
	}
	
	public double getPrice(final int y, final ChartBoundsRect bounds) { 
		if(y < bounds.getY() || maxPriceScale <=0) {
			return -1;
		}
		
		return maxPriceScale - (((maxPriceScale - minPriceScale) * (y - bounds.getY())) / (bounds.getHeightWithoutScale() / 2));
	} 
	
	public int getY(final double price, final ChartBoundsRect bounds) {
		if(price <= 0 || maxPriceScale <= 0) {
			return -1;
		}
		
		return bounds.getY() + (int) Math.round((bounds.getHeightWithoutScale() / 2 ) * (maxPriceScale - price) / (maxPriceScale - minPriceScale));
	}
}
